using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace Image{/// <summary>/// Form1 的摘要说明。/// </summary>public class Form1 : System.Windows.Forms.Form{private System.Windows.Forms.OpenFileDialog openFileDialog1;private System.Windows.Forms.MainMenu mainMenu1;private System.Windows.Forms.MenuItem menuItem1;private System.Windows.Forms.MenuItem menuItem2;private System.Windows.Forms.MenuItem menuItem3;private System.Windows.Forms.MenuItem menuItem4;private System.Windows.Forms.MenuItem menuItem5;private System.Windows.Forms.MenuItem menuItem6;private System.Windows.Forms.MenuItem menuItem7;private System.Windows.Forms.MenuItem menuItem8;private System.Windows.Forms.MenuItem menuItem9;private System.Windows.Forms.MenuItem menuItem10;/// <summary>/// 必需的设计器变量。/// </summary>private System.ComponentModel.Container components = null;public Form1(){//// Windows 窗体设计器支持所必需的//InitializeComponent();//// TODO: 在 InitializeComponent 调用后添加任何构造函数代码//}/// <summary>/// 清理所有正在使用的资源。/// </summary>protected override void Dispose( bool disposing ){if( disposing ){if (components != null) {components.Dispose();}}base.Dispose( disposing );}#region Windows 窗体设计器生成的代码/// <summary>/// 设计器支持所需的方法 - 不要使用代码编辑器修改/// 此方法的内容。/// </summary>private void InitializeComponent(){this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();this.mainMenu1 = new System.Windows.Forms.MainMenu();this.menuItem1 = new System.Windows.Forms.MenuItem();this.menuItem2 = new System.Windows.Forms.MenuItem();this.menuItem3 = new System.Windows.Forms.MenuItem();this.menuItem4 = new System.Windows.Forms.MenuItem();this.menuItem5 = new System.Windows.Forms.MenuItem();this.menuItem6 = new System.Windows.Forms.MenuItem();this.menuItem7 = new System.Windows.Forms.MenuItem();this.menuItem8 = new System.Windows.Forms.MenuItem();this.menuItem9 = new System.Windows.Forms.MenuItem();this.menuItem10 = new System.Windows.Forms.MenuItem();// // openFileDialog1// this.openFileDialog1.Filter = "Image files (JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png|" " JPeg files (*.jpg;*.jpeg)|*.jpg;*.jpeg |GIF files (*.gif)|*.gif |BMP files (*.b" "mp)|*.bmp|Tiff files (*.tif;*.tiff)|*.tif;*.tiff|Png files (*.png)| *.png |All f" "iles (*.*)|*.*";// // mainMenu1// this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1, this.menuItem5});// // menuItem1// this.menuItem1.Index = 0;this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2, this.menuItem3, this.menuItem4});this.menuItem1.Text = "文件(&F)";// // menuItem2// this.menuItem2.Index = 0;this.menuItem2.Text = "打开(&O)";this.menuItem2.Click = new System.EventHandler(this.menuItem2_Click);// // menuItem3// this.menuItem3.Index = 1;this.menuItem3.Text = "-";// // menuItem4// this.menuItem4.Index = 2;this.menuItem4.Text = "退出(&E)";this.menuItem4.Click = new System.EventHandler(this.menuItem4_Click);// // menuItem5// this.menuItem5.Index = 1;this.menuItem5.MdiList = true;this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem6, this.menuItem7, this.menuItem8, this.menuItem9, this.menuItem10});this.menuItem5.Text = "视图(&V)";// // menuItem6// this.menuItem6.Index = 0;this.menuItem6.Text = "层叠窗口(&C)";this.menuItem6.Click = new System.EventHandler(this.menuItem6_Click);// // menuItem7// this.menuItem7.Index = 1;this.menuItem7.Text = "-";// // menuItem8// this.menuItem8.Index = 2;this.menuItem8.Text = "水平平铺窗口(&H)";this.menuItem8.Click = new System.EventHandler(this.menuItem8_Click);// // menuItem9// this.menuItem9.Index = 3;this.menuItem9.Text = "-";// // menuItem10// this.menuItem10.Index = 4;this.menuItem10.Text = "垂直平铺窗口(&V)";this.menuItem10.Click = new System.EventHandler(this.menuItem10_Click);// // Form1// this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);this.ClientSize = new System.Drawing.Size(368, 206);this.IsMdiContainer = true;this.Menu = this.mainMenu1;this.Name = "Form1";this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;this.Text = "演示多图像浏览";}#endregion/// <summary>/// 应用程序的主入口点。/// </summary>[STAThread]static void Main() {Application.Run(new Form1());}private void menuItem2_Click(object sender, System.EventArgs e){//响应“打开”菜单,浏览图像if(this.openFileDialog1.ShowDialog()==DialogResult.OK){ //取得图像文件名string MyFileName=this.openFileDialog1.FileName; //创建显示图像子窗体Form2 NewForm=new Form2(); //将文件名数据传递给子窗体NewForm.FileName=MyFileName; //设置子窗体的父窗体NewForm.MdiParent=this; //显示子窗体 NewForm.Show();}}private void menuItem4_Click(object sender, System.EventArgs e){//响应“退出”菜单if(MessageBox.Show("确定要退出程序吗?","信息提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.OK){this.Close();Application.Exit();}}private void menuItem6_Click(object sender, System.EventArgs e){//响应“层叠窗口”菜单this.LayoutMdi(MdiLayout.Cascade);}private void menuItem8_Click(object sender, System.EventArgs e){//响应“水平平铺窗口”菜单this.LayoutMdi(MdiLayout.TileHorizontal);}private void menuItem10_Click(object sender, System.EventArgs e){////响应“垂直平铺窗口”菜单this.LayoutMdi(MdiLayout.TileVertical);}}}
评论